<?php

use Faker\Factory as Faker;
use App\Models\PayRecord;
use App\Repositories\PayRecordRepository;

trait MakePayRecordTrait
{
    /**
     * Create fake instance of PayRecord and save it in database
     *
     * @param array $payRecordFields
     * @return PayRecord
     */
    public function makePayRecord($payRecordFields = [])
    {
        /** @var PayRecordRepository $payRecordRepo */
        $payRecordRepo = App::make(PayRecordRepository::class);
        $theme = $this->fakePayRecordData($payRecordFields);
        return $payRecordRepo->create($theme);
    }

    /**
     * Get fake instance of PayRecord
     *
     * @param array $payRecordFields
     * @return PayRecord
     */
    public function fakePayRecord($payRecordFields = [])
    {
        return new PayRecord($this->fakePayRecordData($payRecordFields));
    }

    /**
     * Get fake data of PayRecord
     *
     * @param array $postFields
     * @return array
     */
    public function fakePayRecordData($payRecordFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'amount' => $fake->word,
            'channel' => $fake->word,
            'out_trade_no' => $fake->word,
            'extra_param' => $fake->text,
            'trade_state' => $fake->word,
            'transaction_id' => $fake->word,
            'payer_openid' => $fake->word,
            'payer_id' => $fake->randomDigitNotNull,
            'notify_data' => $fake->text,
            'notify_at' => $fake->word,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $payRecordFields);
    }
}
